import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm";

@Index("openid", ["openid"], { unique: true })
@Index("unionid", ["unionid"], { unique: true })
@Entity("user", { schema: "cabinet" })
export class User {
  @PrimaryGeneratedColumn({ type: "int", name: "user_id", unsigned: true })
  userId: number;

  @Column("varchar", { name: "nickname", comment: "昵称", length: 30 })
  nickname: string;

  @Column("varchar", { name: "avatar", comment: "头像", length: 150 })
  avatar: string;

  @Column("tinyint", { name: "gender", default: () => "'0'" })
  gender: number;

  @Column("varchar", {
    name: "openid",
    nullable: true,
    unique: true,
    comment: "openid",
    length: 64,
  })
  openid: string | null;

  @Column("varchar", {
    name: "unionid",
    nullable: true,
    unique: true,
    comment: "unionid",
    length: 64,
  })
  unionid: string | null;

  @Column("varchar", { name: "session_key", length: 40 })
  sessionKey: string;

  @Column("tinyint", {
    name: "client_source",
    unsigned: true,
    default: () => "'0'",
  })
  clientSource: number;

  @Column("int", {
    name: "register_time",
    comment: "注册时间",
    unsigned: true,
    default: () => "'0'",
  })
  registerTime: number;

  @Column("int", {
    name: "last_login_time",
    comment: "最后登录时间",
    unsigned: true,
    default: () => "'0'",
  })
  lastLoginTime: number;
}
